package com.jh.tools.common.string;

import android.text.TextUtils;

import com.jh.tools.base.BaseApp;

import java.text.MessageFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by niejiahuan on 2016/5/31.
 * 字符串工具类
 */
public class StringUtils {
    /**
     * 是否为空
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        return str == null || TextUtils.isEmpty(str);
    }
    /**
     * 将规定值，替换成要替换滴值
     * */
    public static String format(String needReplace, int res) {
        String str = BaseApp.getmContext().getString(res);
        if (isEmpty(str)) {
            str =MessageFormat.format(str, needReplace);
        }
        return str;
    }
    public boolean isNumber(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }
    /**
     * 将规定值，替换成要替换
     * */
    public static String format(Object[] params, int res) {
        String str = BaseApp.getmContext()
                .getString(res);
        if (isEmpty(str)) {
            str=MessageFormat.format(str, params);
        }
        return str;
    }
}
